<?php


namespace app\system\controller;

class Dynamic extends AdminBase
{
	public function getlist()
	{
		$options = $this->request->get();
		$options["limit"] = $this->page_size;
		$options["page"] = $this->page_no;
		$result = \app\system\service\DynamicService::getlist($options);
		$this->response($result["code"], "获取成功", $result["data"], ["count", $result["count"]], ["pages", $result["pages"]]);
	}
	public function getinfo()
	{
		$options = \think\facade\Request::get();
		$result = \app\system\service\DynamicService::getinfo($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "获取成功", $result["data"]);
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function get_comment_list($dynamic_id = 0, $sub_comment_length = 5, $isAll = false)
	{
		$options = $this->request->get();
		$options["limit"] = $this->page_size;
		$options["page"] = $this->page_no;
		$options["dynamic_id="] = $dynamic_id;
		$options["sub_comment_length"] = $sub_comment_length;
		$options["isAll"] = $isAll;
		$result = \app\system\service\DynamicService::get_comment_list($options);
		$this->response($result["code"], "获取成功", $result["data"], ["count", $result["count"]], ["pages", $result["pages"]]);
	}
	public function get_comment_info()
	{
		$options = \think\facade\Request::get();
		$result = \app\system\service\DynamicService::get_comment_info($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "获取成功", $result["data"]);
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function get_sub_comment_list($dynamic_id, $pid)
	{
		$options = $this->request->get();
		$options["limit"] = $this->page_size;
		$options["page"] = $this->page_no;
		$options["dynamic_id"] = $dynamic_id;
		$options["pid"] = $pid;
		$result = \app\system\service\DynamicService::get_sub_comment_list($options);
		$this->response($result["code"], "获取成功", $result["data"], ["count", $result["count"]], ["pages", $result["pages"]]);
	}
	public function dynamic_trials()
	{
		$options = $this->request->post();
		$validate = \think\Validate::make(["id" => "require", "status" => "require"], ["id.require" => "id 不能为空", "status.require" => "status 不能为空"]);
		if (!$validate->check($options)) {
			$this->response(\app\system\model\Code::fail, $validate->getError());
		}
		$result = \app\system\service\DynamicService::dynamic_trials($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "审核成功");
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function comment_trials()
	{
		$options = $this->request->post();
		$validate = \think\Validate::make(["id" => "require", "status" => "require"], ["id.require" => "id 不能为空", "status.require" => "status 不能为空"]);
		if (!$validate->check($options)) {
			$this->response(\app\system\model\Code::fail, $validate->getError());
		}
		$result = \app\system\service\DynamicService::comment_trials($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "审核成功");
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function revise_dynamic_info()
	{
		$options = $this->request->post();
		$validate = \think\Validate::make(["id" => "require", "title" => "require", "content" => "require", "cid" => "require"], ["dynamic_id.require" => "id 不能为空", "title.require" => "title 不能为空", "content.require" => "content 不能为空", "cid.require" => "cid 不能为空"]);
		if (!$validate->check($options)) {
			$this->response(\app\system\model\Code::fail, $validate->getError());
		}
		$result = \app\system\service\DynamicService::revise_dynamic_info($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "修改成功");
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function get_classify_list($data_structure = 0)
	{
		$options = $this->request->get();
		$options["limit"] = $this->page_size;
		$options["page"] = $this->page_no;
		$options["data_structure"] = $data_structure;
		$result = \app\system\service\DynamicService::get_classify_list($options);
		$this->response($result["code"], "获取成功", $result["data"], ["count", $result["count"]], ["pages", $result["pages"]]);
	}
	public function add_classify()
	{
		$options = $this->request->post();
		$options["pid"] = 0;
		$validate = \think\Validate::make(["name" => "require", "pid" => "require", "sort" => "require"], ["name.require" => "分类名称不能为空！", "sort.require" => "排序号不能为空！", "pid.require" => "请设置分类层级！"]);
		if (!$validate->check($options)) {
			$this->response(\app\system\model\Code::fail, $validate->getError());
		}
		$result = \app\system\service\DynamicService::add_classify($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "添加成功");
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function get_classify_info()
	{
		$options = \think\facade\Request::get();
		$result = \app\system\service\DynamicService::get_classify_info($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "获取成功", $result["data"]);
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function edit_classify()
	{
		$options = $this->request->post();
		$options["pid"] = 0;
		$validate = \think\Validate::make(["id" => "require", "name" => "require", "pid" => "require", "sort" => "require"], ["id.require" => "分类id不能为空！", "name.require" => "分类名称不能为空！", "sort.require" => "排序号不能为空！", "pid.require" => "请设置分类层级！"]);
		if (!$validate->check($options)) {
			$this->response(\app\system\model\Code::fail, $validate->getError());
		}
		$result = \app\system\service\DynamicService::edit_classify($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "编辑成功");
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function del_classify()
	{
		$options = \think\facade\Request::post();
		$result = \app\system\service\DynamicService::del_classify($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "删除成功");
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function del_dynamic()
	{
		$options = \think\facade\Request::post();
		$result = \app\system\service\DynamicService::del_dynamic($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "删除成功");
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function del_dynamic_comment()
	{
		$options = \think\facade\Request::post();
		$result = \app\system\service\DynamicService::del_dynamic_comment($options);
		if ($result["code"] == 1) {
			$this->response($result["code"], "删除成功");
		} else {
			$this->response($result["code"], $result["msg"]);
		}
	}
	public function get_label_list()
	{
		$options = $this->request->get();
		$options["limit"] = $this->page_size;
		$options["page"] = $this->page_no;
		$result = \app\system\service\DynamicService::get_label_list($options);
		$this->response($result["code"], "获取成功", $result["data"], ["count", $result["count"]], ["pages", $result["pages"]]);
	}
}